package com.myapi.ModelPoker;

import java.io.Serializable;

import com.myapi.client.PotContributionInfo;

/**
 * A PotContribution is another name for a bet. A bet is forced if it is a blind or ante bet, in other words the Player has been forced to make the bet by the Dealer, 
 * and they still get a chance to make a move before the round is complete. When a Player makes a bet, it is added to any existing bets they have made in that betting round. Bets from previous betting rounds are set to complete. 
 * The Dealer determines that the round is complete by calling contributionsMatched() in the TablePot class, which checks that all Players have had a turn (forced is false), or have already folded/mucked, 
 * and that all bets have been equaled (or a Player is all in with a smaller bet).
 * @author Realease by Yoan Olivier 
 *
 */
public class PotContribution implements Serializable{
   
    private Player player;
    private double amount;
    private boolean allIn;
    private boolean forced;  //blinds and antes are forced
    private boolean complete;  //complete for that betting round
    private boolean mucked;  //if the equivalent PlayerHand is mucked
    /**
     * Constructor PotContribution 
     * @param player
     * @param amount of the contribution
     * @param player is allIn
     * @param forced blinds and antes are forced
     */
    public PotContribution(Player player, double amount, boolean allIn, boolean forced) {
        this.player = player;
        setAmount(amount);
        setAllIn(allIn);
        setForced(forced);  //if true, the player still has a chance to bet before the round is deemed finished by the Dealer
        setComplete(false);
        setMucked(false);
    }
    
    public Player getPlayer() {
        return player;
    }
    
    public double getAmount() {
        return amount;
    }
    
    public void setAmount(double amount) {
        this.amount = amount;
    }
    
    public boolean getForced() {
        return forced;
    }
    
    public void setForced(boolean forced) {
        this.forced = forced;
    }
    
    public boolean getAllIn() {
        return allIn;
    }
    
    public void setAllIn(boolean allIn) {
        this.allIn = allIn;
    }
    
    public boolean getComplete() {
        return complete;
    }
    
    public void setComplete(boolean complete) {
        this.complete = complete;
    }
    
    public boolean getMucked() {
        return mucked;
    }
    
    public void setMucked(boolean mucked) {
        this.mucked = mucked;
    }
    
    /**
     * PotContributions are equal if they have the same Player and both are incomplete
     * @param PotContribution 
     * @return they have the same Player and both are incomplete
     */
    public boolean equals(Object o) {
	if(o instanceof PotContribution) {
            PotContribution pC = (PotContribution) o;
            Player pl = pC.getPlayer();
            if(pl.equals(getPlayer()) && pC.getComplete() == getComplete())
                return true;
        }
        return false;
    }
	
    public int hashCode() {
        return getPlayer().hashCode();
    }

	public PotContributionInfo getInfo() {
		PotContributionInfo potContributionInfo =new PotContributionInfo();
		potContributionInfo.setAllIn(this.getAllIn());
		potContributionInfo.setAmount(this.getAmount());
		potContributionInfo.setComplete(this.getComplete());
		potContributionInfo.setForced(this.getForced());
		potContributionInfo.setMucked(this.getMucked());
		potContributionInfo.setPlayer(this.getPlayer().getInfo());
		// TODO Auto-generated method stub
		return potContributionInfo;
	}
    
}
